/**
 * Created by li on 2017/2/20.
 */
//game start menu scene
var GameMenuLayer = cc.Layer.extend({

    ctor:function () {
        this._super();


        //var frame = new cc.SpriteFrame(res.walkRight_small_png,cc.rect(14*i,0,14,16));
        //spriteFrame.push(frame);
        //var animation = new cc.Animation(spriteFrame,delay);
        //var anim = new cc.Animate(animation);
        //cc.animationCache.addAnimation(anim,type);
        //var anim = cc.animationCache.getAnimation(animId);
        //var action = cc.repeatForever(anim);
        //this.mySprite.runAction(action);

        document.body.style.background="#c0c0c0";

        cc.audioEngine.playMusic(res.gameMenu_mp3,true);

        this.bgSprite = new cc.Sprite(res.cartoon_png,cc.rect(1006,1,200,200));
        var scaleX = size.width/this.bgSprite.width;
        var scaleY = size.height/this.bgSprite.height;
        this.bgSprite.attr({
            anchorX:0,
            anchorY:0,
            scaleX:scaleX,
            scaleY:scaleY,
        })
        this.addChild(this.bgSprite);


        var startSpriteNormal = new cc.Sprite(res.startGameUnable_jpg);
        var startSpriteSelected = new cc.Sprite(res.startGameUnable_jpg);
        var startMenuItem = new cc.MenuItemSprite(
            startSpriteNormal,
            startSpriteSelected,
            this.startGame, this);
        startMenuItem.attr({
            y:-150,
            scaleX:2,
            scaleY:2,
        });

        var startMenu = new cc.Menu(startMenuItem);
        this.addChild(startMenu);

        var loadNormal = new cc.Sprite(res.loadGameUnable_jpg);
        var loadSelected = new cc.Sprite(res.loadGameUnable_jpg);
        var loadMenuItem = new cc.MenuItemSprite(
            loadNormal,
            loadSelected,
            this.loadGame, this);
        loadMenuItem.attr({
            y:-250,
            scaleX:2,
            scaleY:2,
        });
        var loadMenu = new cc.Menu(loadMenuItem);
        this.addChild(loadMenu);

        this.titleLabel = new cc.LabelTTF(g.strTitle,"HanWangShinSuMedium",100);
        this.titleLabel.setFontFillColor( cc.color(200, 80, 80, 255));
        this.titleLabel.attr({
            //x:size.width/2,
            //y:size.height-size.height/4,
            x:size.width/2,
            y:-100,
        })
        this.addChild(this.titleLabel);
        this.titleLabel.runAction(cc.moveTo(2,cc.p(size.width/2,size.height-size.height/5*2)));

        //this.addChild(loadMenuItem);

        //this.blink = cc.blink(0.2,1);
        //this.bgSprite.runAction(this.blink);
//        var CheatsEvent = cc.eventManager.addListener({
//            event: cc.EventListener.KEYBOARD,
//            onKeyReleased:function(keyCode,event){
//                //console.log(keyCode);
//
//                if(keyCode==38) {
//
//                    var CheatsEvent = cc.eventManager.addListener({
//                        event: cc.EventListener.KEYBOARD,
//                        onKeyReleased: function (keyCode, event) {
//                            if (keyCode == 38) {
//                                alert('1');
//                            }
//                        }
//                    },self);
//
//                }
//////                    //if(keyCode==38){
////////                        //if(keyCode==40){
//                        //    if(keyCode==40){
//                        //        if(keyCode==37){
//                        //            if(keyCode==39){
//                        //                if(keyCode==37){
//                        //                    if(keyCode==39){
//                        //                        if(keyCode==66){
//                        //                            if(keyCode==65){
//                        //                                if(keyCode==66){
//                        //                                    if(keyCode==65){
//                        //                                        alert('a');
//                        //                                    }
//                        //                                }
//                        //                            }
//                        //                        }
//                        //                    }
//                        //                }
//                        //            }
//                        //        }
//                        //    }
//                        //}
//
//
//
//                    //}
//                //}
//            },
//
//        },this);
        //document.body.addEventListener("keydown",function(e){
        //    if(e.keyCode==38){
        //        document.body.addEventListener("keydown",function(e){
        //            if(e.keyCode==38){
        //                alert('s');
        //            }else{
        //                return;
        //            }
        //        });
        //    }else{
        //        return;
        //    }
        //})

        //},2);
    },
    startGame:function(){
        cc.audioEngine.stopMusic(res.cartoonMusic_mp3);
        g.isLoad = false;
        var transition=new cc.TransitionCrossFade(1,new GameBeginScene());
        cc.director.runScene(transition);
    },
    loadGame:function(){
        cc.audioEngine.stopMusic(res.cartoonMusic_mp3);
        g.isLoad = true;
        var transition=new cc.TransitionCrossFade(1,new GameScene());
        cc.director.runScene(transition);

    }

});


var GameMenuScene = cc.Scene.extend({
    onEnter:function () {
        this._super();
        var layer = new GameMenuLayer();
        this.addChild(layer);
    }
});